package cn.alex.sso.project.mapper;

import cn.alex.sso.project.entity.SysUserDept;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Alex
 * @description 针对表【sys_user_dept(用户和部门关联表)】的数据库操作Mapper
 * @createDate 2024-09-24 17:05:38
 * @Entity cn.alex.sso.project.entity.SysUserDept
 */
public interface SysUserDeptMapper extends BaseMapper<SysUserDept> {

    /**
     * 根据部门ID获取用户ID列表
     *
     * @param deptIdList 部门ID集合
     * @return 应用ID列表
     */
    default List<Long> getUserIdListByDeptId(List<Long> deptIdList) {
        if (CollUtil.isEmpty(deptIdList)) {
            return ListUtil.empty();
        }
        List<SysUserDept> roleClientList = this.selectList(new LambdaQueryWrapper<SysUserDept>()
                .in(SysUserDept::getDeptId, deptIdList)
        );
        return roleClientList.stream().map(SysUserDept::getUserId).distinct().collect(Collectors.toList());
    }
}




